package requests

import (
	"github.com/flaravel/quanlaolao/app/models/promotion"
	"github.com/thedevsaddam/govalidator"
)

func ValidateGroupForm(data promotion.GroupPromotion) map[string][]string {

	rules := govalidator.MapData{
		"name" : []string{"required","max_cn:15"},
		"avatar" : []string{"required","url"},
		"wechat_qrcode" : []string{"required","url"},
		"desc" : []string{"required","max_cn:200"},
		"number" : []string{"required","max:999"},
	}

	messages := govalidator.MapData{
		"name": []string{
			"required:群名称为必填项",
			"max_cn:群名称需小于 15",
		},
		"desc": []string{
			"required:群导语为必填项",
			"max_cn:群导语需小于 200",
		},
		"number": []string{
			"required:群人数为必填项",
			"max:群人数需小于 999",
		},
		"avatar": []string{
			"required:群头像为必填项",
			"url:群头像格式错误",
		},
		"wechat_qrcode": []string{
			"required:群二维码为必填项",
			"url:群二维码格式错误",
		},
	}
	opts := govalidator.Options{
		Data:          &data,
		Rules:         rules,
		TagIdentifier: "valid", // 模型中的 Struct 标签标识符
		Messages:      messages,
	}
	return govalidator.New(opts).ValidateStruct()
}